﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Web.manager
{
    public partial class sysmoduleedit : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Hashtable sysmodule = PhoneBook.Manage.sysModule.get(Request["moduleid"]);
                if (sysmodule == null)
                {
                    throw new Base.CustomException("参数moduleid不正确");
                }
                txb_modulename.Text =sysmodule["modulename"].ToString();
                txb_urladdress.Text = sysmodule["urladdress"].ToString();
                ddl_systemid.SelectedValue = sysmodule["systemid"].ToString();

                ddl_systemid_SelectedIndexChanged(ddl_systemid, new EventArgs());

                ddl_parentid.SelectedValue = sysmodule["parentid"].ToString();
                txb_showxh.Text = sysmodule["showxh"].ToString();
                txb_description.Text = sysmodule["description"].ToString();
            }
        }

        protected void ddl_systemid_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataSet ds = PhoneBook.Manage.sysModule.getTopModule(ddl_systemid.SelectedValue);
            Commons.ControlUtil.BindDDL(ddl_parentid, ds, "modulename", "moduleid", "顶级模块", "");
        }

        protected void btn_save_Click(object sender, EventArgs e)
        {
            Hashtable sysmodule = new Hashtable();
            sysmodule["moduleid"] = Request["moduleid"];

            Hashtable oldSysModule = PhoneBook.Manage.sysModule.get(Commons.StrUtil.FormatValue(Request["moduleid"].ToString()));
            addLog(oldSysModule);

            sysmodule["modulename"] = txb_modulename.Text;
            sysmodule["urladdress"] = txb_urladdress.Text;
            sysmodule["systemid"] = ddl_systemid.SelectedValue;
            sysmodule["parentid"] = ddl_parentid.SelectedValue;
            sysmodule["showxh"] = txb_showxh.Text;
            sysmodule["description"] = txb_description.Text;
            PhoneBook.Manage.sysModule.edit(sysmodule);
            Helper.ShowMessage(u_message, controls.UCMessageType.success, "保存成功");
        }

        //添加日志
        private void addLog(Hashtable sysmodule)
        {
            string content = string.Empty;

            if (sysmodule["modulename"].ToString() != txb_modulename.Text)
                content += string.Format("模块名称:{0}->{1};", sysmodule["modulename"], txb_modulename.Text);

            if (sysmodule["urladdress"].ToString() != txb_urladdress.Text)
                content += string.Format("模块链接:{0}->{1};", sysmodule["urladdress"], txb_urladdress.Text);

            if (sysmodule["systemid"].ToString() != ddl_systemid.SelectedValue)
                content += string.Format("所属系统变更为:{0};", ddl_systemid.SelectedItem.Text);

            if (sysmodule["parentid"].ToString() != ddl_parentid.SelectedValue)
                content += string.Format("上级模块变更为:{0};", ddl_parentid.SelectedItem.Text);

            if (sysmodule["showxh"].ToString() != txb_showxh.Text)
                content += string.Format("显示序号:{0}->{1};", sysmodule["showxh"], txb_showxh.Text);

            if (sysmodule["description"].ToString() != txb_description.Text)
                content += string.Format("描述:{0}->{1};", sysmodule["description"], txb_description.Text);

            if (!string.IsNullOrEmpty(content))
            {
                content = string.Format("修改了模块信息({0})。{1}", sysmodule["modulename"], content);

                AddLog(content);
            }
        }
    }
}